package com.googlecode.jmicroerp.wicket.administrare;

import com.googlecode.jmicroerp.model.Produs;
import com.googlecode.jmicroerp.service.GenericService;
import com.googlecode.jmicroerp.wicket.DefaultViewPage;
import com.googlecode.jmicroerp.wicket.components.grid.ActionButton;
import com.googlecode.jmicroerp.wicket.components.grid.ActionButtons;
import com.googlecode.jmicroerp.wicket.components.grid.ColumnModel;
import com.googlecode.jmicroerp.wicket.components.grid.DefaultActiveGridAction;
import com.googlecode.jmicroerp.wicket.components.grid.DefaultGridAction;
import com.googlecode.jmicroerp.wicket.components.grid.Grid;
import com.googlecode.jmicroerp.wicket.components.grid.PageParameters;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 *
 * @author alex
 */
public class VizualizareProdusePage extends DefaultViewPage {

    @SpringBean(name = "defaultActiveGridAction")
    private DefaultActiveGridAction<Produs> gridAction;
    @SpringBean(name = "genericService")
    private GenericService<Produs> genericService;

    public VizualizareProdusePage() {
        ColumnModel[] grids = {
            new ColumnModel("Denumire", "denumire", String.class),
            new ColumnModel("Pret", "pret", BigDecimal.class),
            new ColumnModel("Ordine", "ordine", BigDecimal.class),
            new ColumnModel("Activ", "activ", Boolean.class),
        };
        List<ColumnModel> columns = Arrays.asList(grids);
        ActionButton deleteButton = new ActionButton("stergere", new PageParameters()) {

            @Override
            public void doAction(Long id) {
                Produs produs = genericService.getById(Produs.class, id);
                produs.setActiv(Boolean.FALSE);
                genericService.update(produs);
                setResponsePage(VizualizareProdusePage.class);
            }
            
        };
        ActionButton actionButton = new ActionButton(new PageParameters(EditareProdusePage.class));
        ActionButtons actionButtons = new ActionButtons(actionButton, deleteButton);
        Grid<Produs> dataGridConsum = new Grid<Produs>("grid", columns, Produs.class, gridAction, actionButtons);
        add(dataGridConsum);
    }
}
